
import { Controller, Get, Post, Put, Body, Query, Param, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { ApiDataResponse } from 'src/common/decorators/apiDataResponse.decorator';
import { UserTool, UserToolType } from 'src/module/system/user/user.decorator';
import { RepeatSubmit } from 'src/common/decorators/repeat-submit.decorator';
import {BusinessType} from "../../../common/constant/business.constant";
import {Operlog} from "../../../common/decorators/operlog.decorator";
import {ProfessionalCourseService} from "./professional-course.service";
import {BaseCourseDto, CreateCourseDto, QueryCourseDto, UpdateCourseDto} from "./dto/profession-course.dto";

@ApiTags('专业关联课程管理')
@Controller('edutation/professional/course')
export class ProfessionalCourseController {
constructor(private readonly professionalCourseService: ProfessionalCourseService) {}

    //============================================专业关联课程

    @ApiOperation({  summary: '获取关联院校列表', })
    @Get('list')
    findAllCourse(@Query() query:any) {
        return this.professionalCourseService.findAllCourse(query);
    }

    @ApiOperation({  summary: '关联课程-详情',    })
    @ApiDataResponse(BaseCourseDto)
    @Get(':id')
    findOneCourse(@Param('id') id: string) {
        return this.professionalCourseService.findOneCourse(+id);
    }

    @ApiOperation({  summary: '新增关联课程', })
    @Post()
    @RepeatSubmit()
    @Operlog({ businessType: BusinessType.INSERT })
    createCourse(@Body() body: CreateCourseDto,@UserTool() { injectCreate }: UserToolType) {
        return this.professionalCourseService.createCourse(injectCreate(body));
    }

    @ApiOperation({  summary: '修改关联课程', })
    @Put()
    @RepeatSubmit()
    @Operlog({ businessType: BusinessType.UPDATE })
    updateCourse(@Body() body: UpdateCourseDto,@UserTool() { injectUpdate }: UserToolType) {
        return this.professionalCourseService.updateCourse(injectUpdate(body));
    }

    @ApiOperation({  summary: '删除关联课程', })
    @Delete(':ids')
    @Operlog({ businessType: BusinessType.DELETE })
    removeCourse(@Param('ids') ids: string) {
        const idList = ids.split(',').map((id) => +id);
        return this.professionalCourseService.removeCourse(idList);
    }



}
